package edu.spec.sms.dao.impl;

import edu.spec.sms.dao.iface.IClazzDao;
import edu.spec.sms.model.Clazz;
import edu.spec.sys.model.enumeration.Status;
import org.madgecko.basic.dao.BaseDao;
import org.madgecko.basic.model.Pager;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class ClazzDao extends BaseDao<Clazz> implements IClazzDao {
	@Override
	public List<Clazz> listInSchoolClazz() {
		String hql = " from Clazz c where c.status=1";
		return this.list(hql);
	}

	@Override
	public Pager<Clazz> findClazzByCon(Status status, String con) {
		String hql = " from Clazz c where 1=1 ";
		if(status!=null){
			hql += " and c.status=" + status.ordinal();
		}
		if(con!=null){
			hql += " and c.name like '%" + con + "%'";
		}
		return this.find(hql);
	}

	@Override
	public Clazz loadByName(String name) {
		String hql = " from Clazz c where c.name=?";
		return (Clazz)this.queryObject(hql, name);
	}
}
